<template>
  <el-dialog
    :title="!dataForm.id ? '新增' : '修改'"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
    <el-form-item label="学校名字" prop="name">
      <el-input v-model="dataForm.name" placeholder="学校名字"></el-input>
    </el-form-item>
    <el-form-item label="类型," prop="type">
      <el-input v-model="dataForm.type" placeholder="类型,"></el-input>
    </el-form-item>
    <el-form-item label="别名," prop="alias">
      <el-input v-model="dataForm.alias" placeholder="别名,"></el-input>
    </el-form-item>
    <el-form-item label="全称," prop="title">
      <el-input v-model="dataForm.title" placeholder="全称,"></el-input>
    </el-form-item>
    <el-form-item label="状态," prop="status">
      <el-input v-model="dataForm.status" placeholder="状态,"></el-input>
    </el-form-item>
    <el-form-item label="扩展属性," prop="parameter">
      <el-input v-model="dataForm.parameter" placeholder="扩展属性,"></el-input>
    </el-form-item>
    <el-form-item label="区域ID1," prop="regionId1">
      <el-input v-model="dataForm.regionId1" placeholder="区域ID1,"></el-input>
    </el-form-item>
    <el-form-item label="区域ID2," prop="regionId2">
      <el-input v-model="dataForm.regionId2" placeholder="区域ID2,"></el-input>
    </el-form-item>
    <el-form-item label="区域ID3," prop="regionId3">
      <el-input v-model="dataForm.regionId3" placeholder="区域ID3,"></el-input>
    </el-form-item>
    <el-form-item label="集团编号," prop="groupId">
      <el-input v-model="dataForm.groupId" placeholder="集团编号,"></el-input>
    </el-form-item>
    <el-form-item label="集团代码," prop="groupCode">
      <el-input v-model="dataForm.groupCode" placeholder="集团代码,"></el-input>
    </el-form-item>
    <el-form-item label="组织属性," prop="pType">
      <el-input v-model="dataForm.pType" placeholder="组织属性,"></el-input>
    </el-form-item>
    <el-form-item label="业务负责人," prop="pDutyman">
      <el-input v-model="dataForm.pDutyman" placeholder="业务负责人,"></el-input>
    </el-form-item>
    <el-form-item label="组织简介," prop="pOrganizeDes">
      <el-input v-model="dataForm.pOrganizeDes" placeholder="组织简介,"></el-input>
    </el-form-item>
    <el-form-item label="类型," prop="pGroupType">
      <el-input v-model="dataForm.pGroupType" placeholder="类型,"></el-input>
    </el-form-item>
    <el-form-item label="级别," prop="pLevel">
      <el-input v-model="dataForm.pLevel" placeholder="级别,"></el-input>
    </el-form-item>
    <el-form-item label="所属教育局," prop="pEduBelong">
      <el-input v-model="dataForm.pEduBelong" placeholder="所属教育局,"></el-input>
    </el-form-item>
    <el-form-item label="创建人," prop="pCreator">
      <el-input v-model="dataForm.pCreator" placeholder="创建人,"></el-input>
    </el-form-item>
    <el-form-item label="所属集团," prop="pGroupBelong">
      <el-input v-model="dataForm.pGroupBelong" placeholder="所属集团,"></el-input>
    </el-form-item>
    <el-form-item label="图标," prop="pLogo">
      <el-input v-model="dataForm.pLogo" placeholder="图标,"></el-input>
    </el-form-item>
    <el-form-item label="教育单位类型：2省级，3市级，4区县级," prop="pEdbType">
      <el-input v-model="dataForm.pEdbType" placeholder="教育单位类型：2省级，3市级，4区县级,"></el-input>
    </el-form-item>
    <el-form-item label="详细地址," prop="pDetailedAddress">
      <el-input v-model="dataForm.pDetailedAddress" placeholder="详细地址,"></el-input>
    </el-form-item>
    <el-form-item label="机构联系人," prop="pAgencyContact">
      <el-input v-model="dataForm.pAgencyContact" placeholder="机构联系人,"></el-input>
    </el-form-item>
    <el-form-item label="联系电话," prop="pContactTel">
      <el-input v-model="dataForm.pContactTel" placeholder="联系电话,"></el-input>
    </el-form-item>
    <el-form-item label="客服电话," prop="pServiceTel">
      <el-input v-model="dataForm.pServiceTel" placeholder="客服电话,"></el-input>
    </el-form-item>
    <el-form-item label="机构官网," prop="pOfficialWebsite">
      <el-input v-model="dataForm.pOfficialWebsite" placeholder="机构官网,"></el-input>
    </el-form-item>
    <el-form-item label="社会信用代码," prop="pSocialCreditCode">
      <el-input v-model="dataForm.pSocialCreditCode" placeholder="社会信用代码,"></el-input>
    </el-form-item>
    <el-form-item label="办学许可证号," prop="pSchoolLicenseNum">
      <el-input v-model="dataForm.pSchoolLicenseNum" placeholder="办学许可证号,"></el-input>
    </el-form-item>
    <el-form-item label="法定代表人," prop="pLegalName">
      <el-input v-model="dataForm.pLegalName" placeholder="法定代表人,"></el-input>
    </el-form-item>
    <el-form-item label="营业执照," prop="pBusinessLicense">
      <el-input v-model="dataForm.pBusinessLicense" placeholder="营业执照,"></el-input>
    </el-form-item>
    <el-form-item label="办学许可证或名办非企业单位登记证," prop="pRunningLicense">
      <el-input v-model="dataForm.pRunningLicense" placeholder="办学许可证或名办非企业单位登记证,"></el-input>
    </el-form-item>
    <el-form-item label="法定代表人身份证正面," prop="pFrontIdCard">
      <el-input v-model="dataForm.pFrontIdCard" placeholder="法定代表人身份证正面,"></el-input>
    </el-form-item>
    <el-form-item label="法定代表人身份证反面," prop="pReverseIdCard">
      <el-input v-model="dataForm.pReverseIdCard" placeholder="法定代表人身份证反面,"></el-input>
    </el-form-item>
    <el-form-item label="创建时间" prop="createTime">
      <el-input v-model="dataForm.createTime" placeholder="创建时间"></el-input>
    </el-form-item>
    <el-form-item label="创建者" prop="createBy">
      <el-input v-model="dataForm.createBy" placeholder="创建者"></el-input>
    </el-form-item>
    <el-form-item label="更新时间" prop="updateTime">
      <el-input v-model="dataForm.updateTime" placeholder="更新时间"></el-input>
    </el-form-item>
    <el-form-item label="更新者" prop="updateBy">
      <el-input v-model="dataForm.updateBy" placeholder="更新者"></el-input>
    </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  export default {
    data () {
      return {
        visible: false,
        dataForm: {
          id: 0,
          name: '',
          type: '',
          alias: '',
          title: '',
          status: '',
          parameter: '',
          regionId1: '',
          regionId2: '',
          regionId3: '',
          groupId: '',
          groupCode: '',
          pType: '',
          pDutyman: '',
          pOrganizeDes: '',
          pGroupType: '',
          pLevel: '',
          pEduBelong: '',
          pCreator: '',
          pGroupBelong: '',
          pLogo: '',
          pEdbType: '',
          pDetailedAddress: '',
          pAgencyContact: '',
          pContactTel: '',
          pServiceTel: '',
          pOfficialWebsite: '',
          pSocialCreditCode: '',
          pSchoolLicenseNum: '',
          pLegalName: '',
          pBusinessLicense: '',
          pRunningLicense: '',
          pFrontIdCard: '',
          pReverseIdCard: '',
          createTime: '',
          createBy: '',
          updateTime: '',
          updateBy: ''
        },
        dataRule: {
          name: [
            { required: true, message: '学校名字不能为空', trigger: 'blur' }
          ],
          type: [
            { required: true, message: '类型,不能为空', trigger: 'blur' }
          ],
          alias: [
            { required: true, message: '别名,不能为空', trigger: 'blur' }
          ],
          title: [
            { required: true, message: '全称,不能为空', trigger: 'blur' }
          ],
          status: [
            { required: true, message: '状态,不能为空', trigger: 'blur' }
          ],
          parameter: [
            { required: true, message: '扩展属性,不能为空', trigger: 'blur' }
          ],
          regionId1: [
            { required: true, message: '区域ID1,不能为空', trigger: 'blur' }
          ],
          regionId2: [
            { required: true, message: '区域ID2,不能为空', trigger: 'blur' }
          ],
          regionId3: [
            { required: true, message: '区域ID3,不能为空', trigger: 'blur' }
          ],
          groupId: [
            { required: true, message: '集团编号,不能为空', trigger: 'blur' }
          ],
          groupCode: [
            { required: true, message: '集团代码,不能为空', trigger: 'blur' }
          ],
          pType: [
            { required: true, message: '组织属性,不能为空', trigger: 'blur' }
          ],
          pDutyman: [
            { required: true, message: '业务负责人,不能为空', trigger: 'blur' }
          ],
          pOrganizeDes: [
            { required: true, message: '组织简介,不能为空', trigger: 'blur' }
          ],
          pGroupType: [
            { required: true, message: '类型,不能为空', trigger: 'blur' }
          ],
          pLevel: [
            { required: true, message: '级别,不能为空', trigger: 'blur' }
          ],
          pEduBelong: [
            { required: true, message: '所属教育局,不能为空', trigger: 'blur' }
          ],
          pCreator: [
            { required: true, message: '创建人,不能为空', trigger: 'blur' }
          ],
          pGroupBelong: [
            { required: true, message: '所属集团,不能为空', trigger: 'blur' }
          ],
          pLogo: [
            { required: true, message: '图标,不能为空', trigger: 'blur' }
          ],
          pEdbType: [
            { required: true, message: '教育单位类型：2省级，3市级，4区县级,不能为空', trigger: 'blur' }
          ],
          pDetailedAddress: [
            { required: true, message: '详细地址,不能为空', trigger: 'blur' }
          ],
          pAgencyContact: [
            { required: true, message: '机构联系人,不能为空', trigger: 'blur' }
          ],
          pContactTel: [
            { required: true, message: '联系电话,不能为空', trigger: 'blur' }
          ],
          pServiceTel: [
            { required: true, message: '客服电话,不能为空', trigger: 'blur' }
          ],
          pOfficialWebsite: [
            { required: true, message: '机构官网,不能为空', trigger: 'blur' }
          ],
          pSocialCreditCode: [
            { required: true, message: '社会信用代码,不能为空', trigger: 'blur' }
          ],
          pSchoolLicenseNum: [
            { required: true, message: '办学许可证号,不能为空', trigger: 'blur' }
          ],
          pLegalName: [
            { required: true, message: '法定代表人,不能为空', trigger: 'blur' }
          ],
          pBusinessLicense: [
            { required: true, message: '营业执照,不能为空', trigger: 'blur' }
          ],
          pRunningLicense: [
            { required: true, message: '办学许可证或名办非企业单位登记证,不能为空', trigger: 'blur' }
          ],
          pFrontIdCard: [
            { required: true, message: '法定代表人身份证正面,不能为空', trigger: 'blur' }
          ],
          pReverseIdCard: [
            { required: true, message: '法定代表人身份证反面,不能为空', trigger: 'blur' }
          ],
          createTime: [
            { required: true, message: '创建时间不能为空', trigger: 'blur' }
          ],
          createBy: [
            { required: true, message: '创建者不能为空', trigger: 'blur' }
          ],
          updateTime: [
            { required: true, message: '更新时间不能为空', trigger: 'blur' }
          ],
          updateBy: [
            { required: true, message: '更新者不能为空', trigger: 'blur' }
          ]
        }
      }
    },
    methods: {
      init (id) {
        this.dataForm.id = id || 0
        this.visible = true
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.id) {
            this.$http({
              url: this.$http.adornUrl(`/eas/easbasicschool/info/${this.dataForm.id}`),
              method: 'get',
              params: this.$http.adornParams()
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.dataForm.name = data.easBasicSchool.name
                this.dataForm.type = data.easBasicSchool.type
                this.dataForm.alias = data.easBasicSchool.alias
                this.dataForm.title = data.easBasicSchool.title
                this.dataForm.status = data.easBasicSchool.status
                this.dataForm.parameter = data.easBasicSchool.parameter
                this.dataForm.regionId1 = data.easBasicSchool.regionId1
                this.dataForm.regionId2 = data.easBasicSchool.regionId2
                this.dataForm.regionId3 = data.easBasicSchool.regionId3
                this.dataForm.groupId = data.easBasicSchool.groupId
                this.dataForm.groupCode = data.easBasicSchool.groupCode
                this.dataForm.pType = data.easBasicSchool.pType
                this.dataForm.pDutyman = data.easBasicSchool.pDutyman
                this.dataForm.pOrganizeDes = data.easBasicSchool.pOrganizeDes
                this.dataForm.pGroupType = data.easBasicSchool.pGroupType
                this.dataForm.pLevel = data.easBasicSchool.pLevel
                this.dataForm.pEduBelong = data.easBasicSchool.pEduBelong
                this.dataForm.pCreator = data.easBasicSchool.pCreator
                this.dataForm.pGroupBelong = data.easBasicSchool.pGroupBelong
                this.dataForm.pLogo = data.easBasicSchool.pLogo
                this.dataForm.pEdbType = data.easBasicSchool.pEdbType
                this.dataForm.pDetailedAddress = data.easBasicSchool.pDetailedAddress
                this.dataForm.pAgencyContact = data.easBasicSchool.pAgencyContact
                this.dataForm.pContactTel = data.easBasicSchool.pContactTel
                this.dataForm.pServiceTel = data.easBasicSchool.pServiceTel
                this.dataForm.pOfficialWebsite = data.easBasicSchool.pOfficialWebsite
                this.dataForm.pSocialCreditCode = data.easBasicSchool.pSocialCreditCode
                this.dataForm.pSchoolLicenseNum = data.easBasicSchool.pSchoolLicenseNum
                this.dataForm.pLegalName = data.easBasicSchool.pLegalName
                this.dataForm.pBusinessLicense = data.easBasicSchool.pBusinessLicense
                this.dataForm.pRunningLicense = data.easBasicSchool.pRunningLicense
                this.dataForm.pFrontIdCard = data.easBasicSchool.pFrontIdCard
                this.dataForm.pReverseIdCard = data.easBasicSchool.pReverseIdCard
                this.dataForm.createTime = data.easBasicSchool.createTime
                this.dataForm.createBy = data.easBasicSchool.createBy
                this.dataForm.updateTime = data.easBasicSchool.updateTime
                this.dataForm.updateBy = data.easBasicSchool.updateBy
              }
            })
          }
        })
      },
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.$http({
              url: this.$http.adornUrl(`/eas/easbasicschool/${!this.dataForm.id ? 'save' : 'update'}`),
              method: 'post',
              data: this.$http.adornData({
                'id': this.dataForm.id || undefined,
                'name': this.dataForm.name,
                'type': this.dataForm.type,
                'alias': this.dataForm.alias,
                'title': this.dataForm.title,
                'status': this.dataForm.status,
                'parameter': this.dataForm.parameter,
                'regionId1': this.dataForm.regionId1,
                'regionId2': this.dataForm.regionId2,
                'regionId3': this.dataForm.regionId3,
                'groupId': this.dataForm.groupId,
                'groupCode': this.dataForm.groupCode,
                'pType': this.dataForm.pType,
                'pDutyman': this.dataForm.pDutyman,
                'pOrganizeDes': this.dataForm.pOrganizeDes,
                'pGroupType': this.dataForm.pGroupType,
                'pLevel': this.dataForm.pLevel,
                'pEduBelong': this.dataForm.pEduBelong,
                'pCreator': this.dataForm.pCreator,
                'pGroupBelong': this.dataForm.pGroupBelong,
                'pLogo': this.dataForm.pLogo,
                'pEdbType': this.dataForm.pEdbType,
                'pDetailedAddress': this.dataForm.pDetailedAddress,
                'pAgencyContact': this.dataForm.pAgencyContact,
                'pContactTel': this.dataForm.pContactTel,
                'pServiceTel': this.dataForm.pServiceTel,
                'pOfficialWebsite': this.dataForm.pOfficialWebsite,
                'pSocialCreditCode': this.dataForm.pSocialCreditCode,
                'pSchoolLicenseNum': this.dataForm.pSchoolLicenseNum,
                'pLegalName': this.dataForm.pLegalName,
                'pBusinessLicense': this.dataForm.pBusinessLicense,
                'pRunningLicense': this.dataForm.pRunningLicense,
                'pFrontIdCard': this.dataForm.pFrontIdCard,
                'pReverseIdCard': this.dataForm.pReverseIdCard,
                'createTime': this.dataForm.createTime,
                'createBy': this.dataForm.createBy,
                'updateTime': this.dataForm.updateTime,
                'updateBy': this.dataForm.updateBy
              })
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.$message({
                  message: '操作成功',
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                    this.visible = false
                    this.$emit('refreshDataList')
                  }
                })
              } else {
                this.$message.error(data.msg)
              }
            })
          }
        })
      }
    }
  }
</script>
